package cc.admin.modules.sys.model;

import cc.admin.modules.sys.entity.SysOrg;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 机构表 存储树结构数据的实体类
 *
 * @Author
 * @Since 2022-07-07
 */
public class SysOrgTreeModel implements Serializable{

    private static final long serialVersionUID = 1L;

    /** 对应sysOrganize中的id字段,前端数据树中的key*/
    private String key;

    /** 对应sysOrganize中的id字段,前端数据树中的value*/
    private String value;

    /** 对应organize_name字段,前端数据树中的title*/
    private String title;


    private boolean isLeaf;
    // 以下所有字段均与SysOrganize相同

    private String id;

    private String parentId;

    private String code;

    private String name;

    private Integer sortBy;

    private String description;

    private String status;

    private String delFlag;

    private String createBy;

    private Date createTime;

    private String updateBy;

    private Date updateTime;

    private List<SysOrgTreeModel> children = new ArrayList<>();


    /**
     * 将sysOrganize对象转换成sysOrganizeTreeModel对象
     * @param sysOrg
     */
	public SysOrgTreeModel(SysOrg sysOrg) {
		this.key = sysOrg.getId();
        this.value = sysOrg.getId();
        this.title = sysOrg.getName();
        this.id = sysOrg.getId();
        this.parentId = sysOrg.getParentId();
        this.code = sysOrg.getCode();
        this.name = sysOrg.getName();
        this.sortBy = sysOrg.getSortBy();
        this.description = sysOrg.getDescription();
        this.status = sysOrg.getStatus();
        this.delFlag = sysOrg.getDelFlag();
        this.createBy = sysOrg.getCreateBy();
        this.createTime = sysOrg.getCreateTime();
        this.updateBy = sysOrg.getUpdateBy();
        this.updateTime = sysOrg.getUpdateTime();
    }

    public boolean getIsLeaf() {
        return isLeaf;
    }

    public void setIsLeaf(boolean isleaf) {
         this.isLeaf = isleaf;
    }

    public String getKey() {
		return key;
	}


	public void setKey(String key) {
		this.key = key;
	}


	public String getValue() {
		return value;
	}


	public void setValue(String value) {
		this.value = value;
	}


	public String getTitle() {
		return title;
	}


	public void setTitle(String title) {
		this.title = title;
	}


	public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public List<SysOrgTreeModel> getChildren() {
        return children;
    }

    public void setChildren(List<SysOrgTreeModel> children) {
        if (children==null){
            this.isLeaf=true;
        }
        this.children = children;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getSortBy() {
        return sortBy;
    }

    public void setSortBy(Integer sortBy) {
        this.sortBy = sortBy;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public SysOrgTreeModel() { }

    /**
     * 重写equals方法
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) {
			return true;
		}
        if (o == null || getClass() != o.getClass()) {
			return false;
		}
        SysOrgTreeModel model = (SysOrgTreeModel) o;
        return Objects.equals(id, model.id) &&
                Objects.equals(parentId, model.parentId) &&
                Objects.equals(code, model.code) &&
                Objects.equals(name, model.name) &&
                Objects.equals(sortBy, model.sortBy) &&
                Objects.equals(description, model.description) &&
                Objects.equals(status, model.status) &&
                Objects.equals(delFlag, model.delFlag) &&
                Objects.equals(createBy, model.createBy) &&
                Objects.equals(createTime, model.createTime) &&
                Objects.equals(updateBy, model.updateBy) &&
                Objects.equals(updateTime, model.updateTime) &&
                Objects.equals(children, model.children);
    }

}
